#ifndef _DWMRICORE_SCLAR_H
#define _DWMRICORE_SCLAR_H


#include "Point3F.h"
#include "defines.h"

#include <stdlib.h>

// TEEM
#include <teem/nrrd.h>
#include <teem/biff.h>

class CScalar
{
public:
	float *m_pScalar;
	uint m_w;
	uint m_h;
	uint m_d;

public:
	CScalar(void);
	~CScalar(void);

public:
	// open the Scalar in Nrrd format
	int OpenScalarFile(const char *pathname, FILE *fp = stdout);
	// save the Scalar as Nrrd format
	int SaveScalarFile(const char *pathname, FILE *fp = stdout);

	// create the Scalar by allocing a memory
	int CreateScalar(const uint w, const uint h, const uint d, 
		const float *pData = NULL);

	// return the pointer of the Scalar data
	float *GetScalarData() { return m_pScalar; }		
	
	// use the following interface to get the Scalar value 
	// of a particular position in the volume
	float GetScalar(const uint x, const uint y, const uint z) const;
	float GetScalar(const float x, const float y, const float z) const;
	float GetScalar(const CPoint3F &p) const;
	float GetScalar(const CPoint3F *p) const;

	inline float GetScalarFast(const uint x, const uint y, const uint z) const {
		return m_pScalar[(z * m_h + y) * m_w + x];
	}
	inline float GetScalarFast(const uint index) {
		return m_pScalar[index];
	}

	// set the scalar value
	void SetScalar(const uint x, const uint y, const uint z, const float s);
	void SetScalar(const uint index, const float s);

	// use the following interface to get the size of the Scalar volume
	uint GetWidth() { return m_w; }
	uint GetHeight() { return m_h; }
	uint GetDepth() { return m_d; }

	bool HasData() { 
		if (m_pScalar)
			return true; 
		else
			return false;
	}

	void Normalize();

};


#endif
